package presentation;

import java.awt.Color;
import java.awt.Font;
import java.text.DecimalFormat;
import java.util.Observable;
import java.util.Observer;

import org.jfree.chart.plot.dial.DialBackground;
import org.jfree.chart.plot.dial.DialCap;
import org.jfree.chart.plot.dial.DialPlot;
import org.jfree.chart.plot.dial.DialPointer;
import org.jfree.chart.plot.dial.DialTextAnnotation;
import org.jfree.chart.plot.dial.StandardDialFrame;
import org.jfree.chart.plot.dial.StandardDialScale;
import org.jfree.data.general.DefaultValueDataset;

public class PBatteryJuiceDial extends DialPlot implements Observer {

	private static final long serialVersionUID = 1L;
	private DefaultValueDataset data;
	private DialTextAnnotation dialValue;
	private int value = 0;
	private DecimalFormat df = new DecimalFormat("#.##");
	private double multiplier = 1.;
	
	public PBatteryJuiceDial()
	{
		/** The dataset. */
		data = new DefaultValueDataset(value);
		this.setDataset(data);
		
		// Dial title
		DialTextAnnotation title = new DialTextAnnotation("State of Charge");
        title.setAngle(90);
        title.setFont(new Font("Arial", Font.BOLD, 20));
        title.setRadius(0.50);
        title.setPaint(Color.lightGray);
        this.addLayer(title);
        
        // Tickmarks and text
        StandardDialScale scale = new StandardDialScale(0, 
        		100, 210, -240, 20, 4);
        scale.setTickRadius(0.93);
        scale.setTickLabelOffset(0.25);
        scale.setTickLabelFont(new Font("Arial", Font.PLAIN, 14));
        scale.setTickLabelPaint(Color.black);
        scale.setTickLabelFormatter(new DecimalFormat("###"));
        this.addScale(0, scale);
        
        // Frame
        StandardDialFrame dialFrame = new StandardDialFrame();
        dialFrame.setBackgroundPaint(Color.lightGray);
        dialFrame.setForegroundPaint(Color.darkGray);
        this.setDialFrame(dialFrame);
        
        //Needle attachment
		DialCap cap = new DialCap();
        cap.setRadius(0.1);
        this.setCap(cap);
        
        // Neddle
        DialPointer needle = new DialPointer.Pointer();
        needle.setRadius(0.9);
        this.addLayer(needle);
        
        // Background
        this.setBackground(new DialBackground(Color.white));
        
        // Text on dial
        dialValue = new DialTextAnnotation(value + "");
        dialValue.setFont(new Font("Arial", Font.BOLD, 30));
        dialValue.setRadius(0.42);
        this.addLayer(dialValue);
	}
	@Override
	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub
		data.setValue((Number) arg1);
	}

}
